package com.tianpengtech.common.generator.model;

import java.util.List;
import org.apache.log4j.Logger;

import com.tianpengtech.common.util.XxxUtil;

public class TableInfo {

    private static final Logger log = Logger.getLogger(TableInfo.class);
    private String tableName;
    private String tableRemark;
    private String modelName;
    private String instanceName;
    private List<ColumnInfo> columns;

    public String getTableName() {
        return tableName;
    }

    public void setTableName(String tableName) {
        this.tableName = tableName;
    }

    public String getTableRemark() {
        return tableRemark;
    }

    public void setTableRemark(String tableRemark) {
        this.tableRemark = tableRemark;
    }

    public String getModelName() {
        return modelName;
    }

    public void setModelName(String modelName) {
        this.modelName = modelName;
    }

    public String getInstanceName() {
        return instanceName;
    }

    public void setInstanceName(String instanceName) {
        this.instanceName = instanceName;
    }

    public List<ColumnInfo> getColumns() {
        return columns;
    }

    public void setColumns(List<ColumnInfo> columns) {
        this.columns = columns;
    }

    public TableInfo(String tableName, String tableRemark) {
        this.tableName = tableName;
        this.tableRemark = tableRemark;
    }

    public TableInfo(String modelName, String tableName, String tableRemark) {
        this.modelName = modelName;
        this.instanceName = XxxUtil.underline2Camel(modelName, true);
        this.tableName = tableName;
        this.tableRemark = tableRemark;
    }

    /*
     * 创建TableInfo信息
     */
    public static TableInfo buildTableInfo(String dbName, String modelName, String tableName, String tableRemark) {
        MetaData data = new MetaData();
        log.info("当前数据库:" + dbName + ",数据库表:" + tableName + ",数据表说明信息:" + tableRemark);
        TableInfo tableInfo = new TableInfo(modelName, tableName, tableRemark);
        tableInfo.setColumns(data.getTableColumns(dbName, tableName));
        return tableInfo;
    }
}
